package com.mxprojects.gui
{
	import com.mxprojects.constructors.ImageDisplay;
	import com.mxprojects.io.Config;
	
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import flash.net.URLRequest;
	import flash.net.navigateToURL;

	public class Icon extends MovieClip
	{
		public static const PRIVATE_MESSAGE:String = "private-message.png";
		public static const WEBSITE:String = "website.png";
		
		private var clickURL:String;
		private var clickFunction:Function;
		private var clickFunctionParams:Array;
		
		public function Icon(iconLocation:String, clickURL:String = "", clickFunction:Function = null, ...clickFunctionParams:Array){
			//set the local vars
			this.clickURL = clickURL;
			this.clickFunction = clickFunction;
			this.clickFunctionParams = clickFunctionParams;
			
			//load the graphics
			var icon:ImageDisplay = new ImageDisplay(iconLocation, "", Config.NETWORK_ICON_WIDTH, Config.NETWORK_ICON_HEIGHT, false);
			addChild(icon);
			
			//handle the mouse stuff
			icon.buttonMode = true;
			icon.addEventListener(MouseEvent.CLICK, handleClick, false, 0, true);
			
			
			//just stop where they need to stop
			//gotoAndStop(type);
			
			//set the value for when they click the icon
			//clickedValue = value;
			//addEventListener(MouseEvent.CLICK, copyToClipboard, false, 0, true);
		}
		
		private function handleClick(event:MouseEvent):void {
			//see if we need to fire a function or a new page
			if(clickURL != ""){
				//do some webpage fun
				navigateToURL(new URLRequest(clickURL), "_blank");
			}
			
			//handle the internal click function
			if(clickFunction != null){
				if(clickFunctionParams.length > 0){
					clickFunction.apply(null, clickFunctionParams);
				}else{
					clickFunction();
				}
			}
		}
		
	}
}